<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>宠物之家 - 用户管理</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <style>
        :root {
            --primary: #FFF9C4;
            --primary-dark: #FFECB3;
            --secondary: #FFFDE7;
            --accent: #FFD54F;
            --text: #5D4037;
            --text-light: #8D6E63;
            --success: #81C784;
            --warning: #FFB74D;
            --danger: #E57373;
            --border: rgba(255, 213, 79, 0.3);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }

        body {
            background-color: var(--secondary);
            color: var(--text);
            display: flex;
            min-height: 100vh;
        }

        /* 侧边导航 */
        .sidebar {
            width: 240px;
            background: var(--primary);
            padding: 20px 0;
            box-shadow: 2px 0 10px rgba(0,0,0,0.05);
            transition: all 0.3s ease;
            z-index: 100;
        }

        .logo {
            padding: 0 20px 20px;
            border-bottom: 1px solid var(--border);
            margin-bottom: 20px;
            text-align: center;
        }

        .logo h1 {
            font-size: 22px;
            color: var(--text);
            font-weight: 600;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .logo i {
            margin-right: 10px;
            color: var(--accent);
        }

        .nav-item {
            padding: 12px 25px;
            margin: 5px 10px;
            border-radius: 8px;
            display: flex;
            align-items: center;
            cursor: pointer;
            transition: all 0.2s;
            color: var(--text-light);
            font-weight: 500;
        }

        .nav-item:hover, .nav-item.active {
            background: var(--primary-dark);
            color: var(--text);
        }

        .nav-item i {
            width: 24px;
            margin-right: 12px;
            font-size: 18px;
        }

        .sub-nav {
            padding-left: 55px;
            margin-top: 5px;
            display: none;
        }

        .sub-nav.active {
            display: block;
        }

        .sub-nav-item {
            padding: 8px 0;
            color: var(--text-light);
            font-size: 14px;
            display: flex;
            align-items: center;
        }

        .sub-nav-item i {
            font-size: 12px;
            margin-right: 8px;
        }

        .sub-nav-item:hover, .sub-nav-item.active {
            color: var(--text);
            font-weight: 500;
        }

        /* 主内容区 */
        .main-content {
            flex: 1;
            display: flex;
            flex-direction: column;
        }

        /* 顶部栏 */
        .topbar {
            background: white;
            padding: 15px 30px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 2px 10px rgba(0,0,0,0.05);
            z-index: 10;
        }

        .search-bar {
            display: flex;
            align-items: center;
            background: var(--secondary);
            border-radius: 24px;
            padding: 8px 15px;
            width: 300px;
        }

        .search-bar input {
            border: none;
            background: transparent;
            padding: 5px 10px;
            width: 100%;
            color: var(--text);
            outline: none;
        }

        .search-bar i {
            color: var(--text-light);
        }

        .user-info {
            display: flex;
            align-items: center;
        }

        .user-info img {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            object-fit: cover;
            margin-right: 10px;
            border: 2px solid var(--primary);
        }

        /* 内容区 */
        .content {
            padding: 25px;
            flex: 1;
            overflow-y: auto;
        }

        /* 用户管理列表样式 */
        .data-container {
            background-color: white;
            border-radius: 12px;
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.05);
            padding: 25px;
            margin-top: 20px;
        }

        .data-header {
            color: #8B6B3D;
            margin-bottom: 25px;
            border-bottom: 2px solid #F5E8C7;
            padding-bottom: 10px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .data-table {
            background-color: white;
            border-collapse: separate;
            border-spacing: 0;
            border-radius: 8px;
            overflow: hidden;
            width: 100%;
        }

        .data-table thead th {
            background-color: #F5E8C7;
            color: #5C4D3D;
            font-weight: 600;
            border: none;
            text-align: center;
            vertical-align: middle;
            padding: 15px 8px;
        }

        .data-table tbody tr {
            height: 60px; /* 增加行高 */
        }

        .data-table tbody td {
            padding: 12px 8px; /* 增加单元格内边距 */
            text-align: center;
            vertical-align: middle;
        }

        .data-table tbody tr:hover {
            background-color: #FFF5E0;
        }

        .btn-add {
            background-color: #E8C07D;
            border-color: #E8C07D;
            color: #5C4D3D;
            padding: 8px 16px;
            font-weight: 500;
        }

        .btn-add:hover {
            background-color: #D4B15F;
            border-color: #D4B15F;
        }

        .btn-edit {
            color: #E8C07D;
            border-color: #E8C07D;
        }

        .btn-edit:hover {
            background-color: #E8C07D;
            color: white;
        }

        .btn-delete {
            color: #E8A07D;
            border-color: #E8A07D;
        }

        .btn-delete:hover {
            background-color: #E8A07D;
            color: white;
        }

        .icon-img {
            max-width: 45px;
            max-height: 45px;
            border-radius: 50%;
            display: block;
            margin: 0 auto;
        }

        .action-buttons {
            display: flex;
            justify-content: center;
            gap: 10px; /* 增加按钮间距 */
        }

        .badge {
            padding: 6px 10px; /* 增加内边距 */
            font-size: 0.85rem;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .sidebar {
                width: 70px;
            }

            .logo h1 span, .nav-item span {
                display: none;
            }

            .logo h1 {
                justify-content: center;
            }

            .nav-item {
                justify-content: center;
                padding: 15px;
            }

            .nav-item i {
                margin-right: 0;
                font-size: 20px;
            }

            .search-bar {
                width: 200px;
            }
        }
        .logout-btn {
            margin-left: 15px;
            padding: 6px 12px;
            background-color: rgba(229, 115, 115, 0.1);
            color: var(--danger);
            border-radius: 6px;
            text-decoration: none;
            font-size: 14px;
            display: flex;
            align-items: center;
            transition: all 0.2s;
            border: 1px solid rgba(229, 115, 115, 0.3);
        }

        .logout-btn i {
            margin-right: 6px;
            font-size: 13px;
        }

        .logout-btn:hover {
            background-color: rgba(229, 115, 115, 0.2);
            color: var(--danger);
            text-decoration: none;
        }
    </style>
</head>
<body>
<!-- 侧边导航 -->
<div class="sidebar">
    <div class="logo">
        <h1><i class="fas fa-paw"></i> <span>宠物邻里互助平台</span></h1>
        <p style="font-size: 13px; color: var(--text-light); margin-top: 5px;">管理后台</p>
    </div>

    <div class="nav-menu">
        <div class="nav-item">
            <i class="fas fa-file-alt"></i>
            <span><a href="${pageContext.request.contextPath}/application/list">申请管理</a></span>
        </div>

        <div class="nav-item active">
            <i class="fas fa-users"></i>
            <span>用户管理</span>
        </div>

        <div class="nav-item">
            <i class="fas fa-home"></i>
            <span>寄养管理</span>
            <i class="fas fa-chevron-down" style="margin-left: auto;"></i>
        </div>
        <div class="sub-nav">
            <div class="sub-nav-item">
                <i class="fas fa-circle"></i>
                <span><a href="${pageContext.request.contextPath}/Admin/hostList">寄养家庭管理</a></span>
            </div>
            <div class="sub-nav-item">
                <i class="fas fa-circle"></i>
                <span><a href="${pageContext.request.contextPath}/Admin/orderList">寄养订单管理</a></span>
            </div>
        </div>


    </div>
</div>

<!-- 主内容区 -->
<div class="main-content">
    <!-- 顶部操作栏 -->
    <div class="topbar">
        <div class="search-bar">
            <i class="fas fa-search"></i>
            <input type="text" placeholder="搜索...">
        </div>

        <div class="user-info">
            <i class="fas fa-bell" style="font-size: 18px; margin-right: 20px; color: var(--text-light);"></i>
            <img src="https://randomuser.me/api/portraits/women/43.jpg" alt="管理员">
            <span>张管理员</span>
            <a href="${pageContext.request.contextPath}/user/logout" class="logout-btn">
                <i class="fas fa-sign-out-alt"></i> 退出
            </a>
        </div>
    </div>

    <!-- 内容区 -->
    <div class="content">
        <div class="data-container">
            <div class="data-header">
                <h1><i class="bi bi-people-fill"></i> 用户管理列表</h1>
                <a href="${pageContext.request.contextPath}/user/add" class="btn btn-add">
                    <i class="bi bi-plus-circle"></i> 添加用户
                </a>
            </div>

            <div class="table-responsive">
                <table class="data-table table-hover">
                    <thead>
                    <tr>
                        <th>用户名</th>
                        <th>密码</th>
                        <th>电子邮箱</th>
                        <th>手机号码</th>
                        <th>头像</th>
                        <th>信誉分</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${userList}" var="user">
                        <tr>
                            <td>${user.username}</td>
                            <td>${user.password}</td>
                            <td>${user.email}</td>
                            <td>${user.phone}</td>
                            <td>
                                <c:if test="${not empty user.icon}">
                                    <img src="${user.icon}" alt="用户头像" class="icon-img">
                                </c:if>
                            </td>
                            <td>
                                <span class="badge bg-warning text-dark">${user.trust_score}</span>
                            </td>
                            <td>
                                <div class="action-buttons">
                                    <a href="${pageContext.request.contextPath}/user/edit/${user.user_id}"
                                       class="btn btn-sm btn-edit">
                                        <i class="bi bi-pencil"></i> 编辑
                                    </a>
                                    <a href="${pageContext.request.contextPath}/user/delete?user_id=${user.user_id}"
                                       class="btn btn-sm btn-delete"
                                       onclick="return confirm('确定要删除此用户吗？')">
                                        <i class="bi bi-trash"></i> 删除
                                    </a>
                                </div>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<!-- Bootstrap JS Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

<script>
    // 导航菜单交互
    const navItems = document.querySelectorAll('.nav-item');

    navItems.forEach(item => {
        // 点击导航项
        item.addEventListener('click', function() {
            // 移除所有活动项
            navItems.forEach(nav => nav.classList.remove('active'));

            // 设置当前项为活动状态
            this.classList.add('active');

            // 切换子菜单显示
            const subNav = this.nextElementSibling;
            if (subNav && subNav.classList.contains('sub-nav')) {
                subNav.classList.toggle('active');
            }
        });

        // 子菜单项点击
        const subNavItems = item.nextElementSibling?.querySelectorAll('.sub-nav-item');
        if (subNavItems) {
            subNavItems.forEach(subItem => {
                subItem.addEventListener('click', function(e) {
                    e.stopPropagation();
                    subNavItems.forEach(i => i.classList.remove('active'));
                    this.classList.add('active');
                });
            });
        }
    });
</script>
</body>
</html>